import Vue from 'vue'
import Vuex from 'vuex'
import app from './app'

Vue.use(Vuex)

// 自动注入modules下的模块
const modulesFiles = import.meta.webpackContext('./modules', {
    recursive: true,
    regExp: /\.js$/
})
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
    const value = modulesFiles(modulePath)
    modules[moduleName] = value.default
    return modules
}, {})

const store = new Vuex.Store({
    modules,
    ...app
})

export default store
